// $Id: uuid_ptr.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#ifndef XPCOM_IMPL_UUID_PTR_HPP
#define XPCOM_IMPL_UUID_PTR_HPP

#include <xpcom/config.hpp>
#include <boost/noncopyable.hpp>
#include <xpcom/uuid.hpp>

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_PREFIX
#endif

namespace xpcom {
namespace impl {

//
// XPCOM implementation argument translators.
// Note: The out/inout arguments must not be null.
//
// uuid_ptr_in(const uuid*) --> const uuid&
// uuid_ptr_out(uuid**) --> uuid&
// uuid_ptr_inout(uuid**) --> uuid&
//
// Note: null pointer is mapped to uuid::nil
//

XPCOM_FORCEINLINE
const uuid& uuid_ptr_in(const uuid* id)
{
    return id ? *id : uuid::nil;
}

class uuid_ptr_out : boost::noncopyable
{
public:
    XPCOM_DECL explicit uuid_ptr_out(uuid** id);
    XPCOM_DECL ~uuid_ptr_out();

    XPCOM_FORCEINLINE
    operator uuid&()
    {
        return val_;
    }

    XPCOM_FORCEINLINE
    void operator=(const uuid& retval)
    {
        val_ = retval;
    }

private:
    uuid** id_;
    uuid val_;
};

class uuid_ptr_inout : boost::noncopyable
{
public:
    XPCOM_DECL explicit uuid_ptr_inout(uuid** id);
    XPCOM_DECL ~uuid_ptr_inout();

    XPCOM_FORCEINLINE
    operator uuid&()
    {
        return val_;
    }

private:
    uuid** id_;
    uuid val_;
};

} // namespace xpcom::impl
} // namespace xpcom

#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_SUFFIX
#endif

#endif // XPCOM_IMPL_UUID_PTR_HPP
